package iblink.core;

import iblink.util.Constants.Right;
import iblink.util.Constants.SecType;

import java.util.Date;

public class Option implements ISecurity {

	private static SecType SEC_TYPE = SecType.OPTION;

	private ISecurity underlying;

	private String symbol;

	private double strikePrice;

	private Date expirationDate;

	private Right right;

	public Option(ISecurity underlying, String symbol, Right right,
			double strikePrice, Date expirationDate) {
		this.underlying = underlying;
		this.symbol = symbol;
		this.strikePrice = strikePrice;
		this.right = right;
		this.expirationDate = expirationDate;
	}

	@Override
	/**
	 * generated code
	 */
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((expirationDate == null) ? 0 : expirationDate.hashCode());
		result = prime * result + ((right == null) ? 0 : right.hashCode());
		long temp;
		temp = Double.doubleToLongBits(strikePrice);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result
				+ ((underlying == null) ? 0 : underlying.hashCode());
		return result;
	}

	@Override
	/**
	 * generated code
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Option other = (Option) obj;
		if (expirationDate == null) {
			if (other.expirationDate != null)
				return false;
		} else if (!expirationDate.equals(other.expirationDate))
			return false;
		if (right != other.right)
			return false;
		if (Double.doubleToLongBits(strikePrice) != Double
				.doubleToLongBits(other.strikePrice))
			return false;
		if (underlying == null) {
			if (other.underlying != null)
				return false;
		} else if (!underlying.equals(other.underlying))
			return false;
		return true;
	}

	public String toString() {
		return getClass().getSimpleName() + "[underlying[" + underlying
				+ "] symbol[" + symbol + "] strikePrice[" + strikePrice
				+ "] right[" + right + "] expirationDate[" + expirationDate
				+ "]]";
	}

	public Right getRight() {
		return right;
	}

	public ISecurity getUnderlying() {
		return underlying;
	}

	public double getStrikePrice() {
		return strikePrice;
	}

	public Date getExpirationDate() {
		return expirationDate;
	}

	@Override
	public SecType getSecType() {
		return SEC_TYPE;
	}
}
